import pandas as pd
from scipy.stats import shapiro, kruskal

# 读取数据文件
df = pd.read_csv("C:\\Users\\www11\\Desktop\\学校\\学术\\medical\\mediacal-cases\\10\\10-5.csv")

# 提取各组的吞噬率数据并去除缺失值
group_a = df['phag_a'].dropna().values
group_b = df['phag_b'].dropna().values
group_c = df['phag_c'].dropna().values

# 执行Shapiro-Wilk正态性检验
print("Shapiro-Wilk正态性检验结果：")
for group, name in zip([group_a, group_b, group_c], ['A', 'B', 'C']):
    if len(group) < 3:
        print(f"组{name}样本量不足，无法进行检验")
        continue
    stat, p = shapiro(group)
    print(f"组{name}: W = {stat:.4f}, p = {p:.4f}")

# 执行Kruskal-Wallis H检验
h_stat, p_value = kruskal(group_a, group_b, group_c)

# 输出检验结果
print("\nKruskal-Wallis H检验结果：")
print(f"H统计量 = {h_stat:.4f}")
print(f"P值 = {p_value:.4f}")

if p_value < 0.05:
    print("结论：P值小于0.05，拒绝原假设，认为不同实验条件对吞噬率的影响有显著差异。")
else:
    print("结论：P值大于等于0.05，无法拒绝原假设，认为不同实验条件对吞噬率无显著差异。")